package cn.edu.nit.sys.controller;

import cn.edu.nit.sys.entity.Teacher;
import cn.edu.nit.sys.service.TeacherService;
import cn.edu.nit.sys.utils.R;
import cn.edu.nit.sys.vo.TeacherVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author xiaobai
 * @Date 2022/10/1 14:15
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @GetMapping
    public R getList(Page<Teacher> page, TeacherVO teacherVO) {
        return teacherService.getList(page, teacherVO);
    }

    @PostMapping
    public R addTeacher(@RequestBody Teacher teacher) {
        return teacherService.add(teacher);
    }

    @PutMapping
    public R updateTeacher(@RequestBody Teacher teacher) {
        return teacherService.updateById(teacher) ? R.ok("修改成功") : R.error("修改失败");
    }

    @DeleteMapping("/{id}")
    public R delTeacher(@PathVariable("id")Long id) {
        return teacherService.removeById(id) ? R.ok("删除成功") : R.error("删除失败");
    }
}
